001 /* 002 * Copyright (c) 2005 Stephen J. McConnell 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.metro.tools; 020 021 import java.util.ArrayList; 022 import java.util.List; 023 024 import net.dpml.metro.info.CategoryDescriptor; 025 026 import net.dpml.metro.info.Priority; 027 028 import org.apache.tools.ant.BuildException; 029 030 /** 031 * Datatype supporting the declaration of a logging channel at the level of a component type. 032 * 033 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 034 * @version 1.1.0 035 */ 036 public class CategoriesDescriptorDataType 037 { 038 private List m_categories = new ArrayList(); 039 040 /** 041 * Create a new services datatype. 042 * @return a new services datatype 043 */ 044 public CategoryDescriptorDataType createCategory() 045 { 046 CategoryDescriptorDataType data = new CategoryDescriptorDataType(); 047 m_categories.add( data ); 048 return data; 049 } 050 051 CategoryDescriptor[] getCategoryDescriptors() 052 { 053 CategoryDescriptorDataType[] entries = 054 (CategoryDescriptorDataType[]) m_categories.toArray( new CategoryDescriptorDataType[0] ); 055 CategoryDescriptor[] categories = new CategoryDescriptor[ entries.length ]; 056 for( int i=0; i<entries.length; i++ ) 057 { 058 CategoryDescriptorDataType data = entries[i]; 059 categories[i] = data.getCategoryDescriptor(); 060 } 061 return categories; 062 } 063 064 /** 065 * Description of a single logging category. 066 */ 067 public class CategoryDescriptorDataType 068 { 069 private String m_name; 070 private Priority m_priority; 071 072 /** 073 * Set the service classname. 074 * @param name the name of the service interface class 075 */ 076 public void setName( final String name ) 077 { 078 if( null == name ) 079 { 080 throw new NullPointerException( "name" ); 081 } 082 m_name = name; 083 } 084 085 /** 086 * Set the service version. 087 * @param spec the version value 088 */ 089 public void setPriority( final String spec ) 090 { 091 if( null == spec ) 092 { 093 throw new NullPointerException( "spec" ); 094 } 095 m_priority = Priority.parse( spec ); 096 } 097 098 CategoryDescriptor getCategoryDescriptor() 099 { 100 if( null == m_name ) 101 { 102 throw new BuildException( "Missing category 'name' attribute." ); 103 } 104 else 105 { 106 return new CategoryDescriptor( m_name, m_priority, null ); 107 } 108 } 109 } 110 }